a11y: Convenience API for referencing ATSPI root node
authorEmmanuele Bassi <ebassi@gnome.org>
Sat, 10 Oct 2020 12:23:21 +0000 (13:23 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 12 Oct 2020 15:19:32 +0000 (16:19 +0100)
We turn the root node into a reference fairly often, so it's worth it to
have a utility function that does this for us.

gtk/a11y/gtkatspicontext.c
gtk/a11y/gtkatspiroot.c
gtk/a11y/gtkatspirootprivate.h

index c1448b6e22b2b87f4a7093f79bf8ead5420dab9c..1567a665d24d6496830fc462e3626d6462e3d401 100644 (file)
@@ -279,11 +279,8 @@ handle_accessible_method (GDBusConnection       *connection,
     }
   else if (g_strcmp0 (method_name, "GetApplication") == 0)
     {
-      const char *name, *path;
-
-      gtk_at_spi_root_get_application (self->root, &name, &path);
-
-      g_dbus_method_invocation_return_value (invocation, g_variant_new ("((so))", name, path));
+      g_dbus_method_invocation_return_value (invocation,
+                                             g_variant_new ("((so))", gtk_at_spi_root_to_ref (self->root)));
     }
   else if (g_strcmp0 (method_name, "GetChildAtIndex") == 0)
     {
@@ -409,10 +406,7 @@ handle_accessible_get_property (GDBusConnection       *connection,
 
       if (parent == NULL)
         {
-          const char *name, *path;
-
-          gtk_at_spi_root_get_application (self->root, &name, &path);
-          res = g_variant_new ("(so)", name, path);
+          res = gtk_at_spi_root_to_ref (self->root);
         }
       else
         {
index 2330852a589f73a93d795f4b8d50abcc30e4e5db..a3b3a4f9fb25e0c355940fe4c2865fa0906cc3ea 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "gtkatspicontextprivate.h"
 #include "gtkatspiprivate.h"
+#include "gtkatspiutilsprivate.h"
 
 #include "gtkdebug.h"
 #include "gtkwindow.h"
@@ -568,15 +569,21 @@ gtk_at_spi_root_get_cache (GtkAtSpiRoot *self)
   return self->cache;
 }
 
-void
-gtk_at_spi_root_get_application (GtkAtSpiRoot *self,
-                                 const char **name,
-                                 const char **path)
+/*< private >
+ * gtk_at_spi_root_to_ref:
+ * @self: a #GtkAtSpiRoot
+ *
+ * Returns an ATSPI object reference for the #GtkAtSpiRoot node.
+ *
+ * Returns: (transfer floating): a #GVariant with the root reference
+ */
+GVariant *
+gtk_at_spi_root_to_ref (GtkAtSpiRoot *self)
 {
-  g_return_if_fail (GTK_IS_AT_SPI_ROOT (self));
+  g_return_val_if_fail (GTK_IS_AT_SPI_ROOT (self), NULL);
+
+  if (self->desktop_path == NULL)
+    return gtk_at_spi_null_ref ();
 
-  if (name != NULL)
-    *name = self->desktop_name;
-  if (path != NULL)
-    *path = self->desktop_path;
+  return g_variant_new ("(so)", self->desktop_name, self->desktop_path);
 }
index 268c8a161fb4a144e55bfa9c0c95efefeeca5808..0ce5e6b6935eda37036f850e100591adf47f3f77 100644 (file)
@@ -39,9 +39,7 @@ gtk_at_spi_root_get_connection (GtkAtSpiRoot *self);
 GtkAtSpiCache *
 gtk_at_spi_root_get_cache (GtkAtSpiRoot *self);
 
-void
-gtk_at_spi_root_get_application (GtkAtSpiRoot *self,
-                                 const char **name,
-                                 const char **path);
+GVariant *
+gtk_at_spi_root_to_ref (GtkAtSpiRoot *self);
 
 G_END_DECLS